<style>
.comment .btnDel {
	position: absolute;
	right: 0;
	top: 10px;
}

.thebignoob {
	color: #76879b;
	font-size: 10px;
	margin: 5px;
	font-family: "Lucida Grande", Verdana, Helvetica, Arial, sans-serif;
	font-size: 11px;
}
</style>

<script type="text/javascript">

/* function deactiveCollape(){
	if( document.getElementById('txtCmt').value != "" ){
		document.getElementById('popCmtLink').removeAttribute('href');
	}
 } */


$(document).on("click", ".btnDel", function () {	
    var delID = $(this).data('id');
    $(".modal-body #delID").val( delID );
});
						
function removeComment(){		
	form = document.getElementById("deleteModal");	
	form.submit();
}

function removePost(){	
	form = document.getElementById("deletePostForm");	
	form.submit();
}
</script>



<div class="mainbar col-md-offset-4">


	<div class="article">
		<h2>
			<span><?php echo $detail['Post']['title']; ?></span>
		</h2>
		<p class="infopost">
			
			<?php echo date ( 'F j, o', strtotime ( $detail ['Post'] ['created'] ) ); ?>
			<span>&nbsp;&bull;&nbsp;</span> Posted by <a
				href="/adminposts/profile/<?php echo $detail['Post']['user_id']; ?>"><?php echo $poster['Poster']['username']; ?></a>
			&nbsp;|&nbsp; with <a id="abc" href="#commentListID"><?php echo count($comments); ?> Comments</a>

		</p>
		<img src="<?php echo $detail['Post']['thumbnail']; ?>"
			style="max-height: 300px; max-width: 400px;" alt="" class="fl" />
		<div class="clr"></div>

		<div align="justify"><?php echo $detail['Post']['body']; ?></div>
		<!-- <p>
			Tagged: <a href="#">orci</a>, <a href="#">lectus</a>, <a href="#">varius</a>,
			<a href="#">turpis</a>
		</p> -->
		<p>
			
			
			<?php if($isAuthor): ?>
			 	<span>&nbsp;&bull;&nbsp;</span> <a
				href="/adminposts/edit/<?php echo $detail['Post']['id']; ?>"><strong>Edit</strong></a>
			<span>&nbsp;&bull;&nbsp;</span> <a href="#" data-toggle="modal"
				data-target=".del-post-modal"><strong>Delete</strong></a>
			<?php endif; ?>
				</p>

		<div class="btn-group">
			<button type="button" class="btn btn-default"
				onclick="window.location.assign('/');">Home page</button>
			<?php if($isAuthor):?>			
			<button type="button" class="btn btn-default"
				onclick="window.location.assign('/adminposts/profile/<?php echo $detail['Post']['user_id'];?>');">
				Manage page</button>
			<?php endif;?>
		</div>


	</div>

	<!-- ADD COMMENT -->
	<div class="article">
		<h2>
			<span>Leave a</span> Reply
		</h2>
		<form method="post" action="/comments/add" class="form-horizontal">
			<input type="hidden" name="post_id"
				value="<?php echo $detail['Post']['id']; ?>" />
			<div class="form-group">
				<div class="col-md-12">
					<a id="popCmtLink" data-toggle="collapse"
						data-parent="#openComment" href="#openThis"> <textarea id="txtCmt"
							name="content" rows="4" cols="50" required="required"
							onclick="deactiveCollape();" placeholder="Your comment ~~~"
							class="form-control"></textarea>
					</a>
				</div>
			</div>
			<div id="openThis" class="panel-collapse collapse">
				<!-- <div id="openThis" class=""> -->
				<div class="form-group">
					<div class="col-md-12">
						<div class="input-group">
							<input type="text" name="fullname" required="required"
								placeholder="Your name" class="form-control"
								value="<?php if($this->Session->check('AdminLogin')) { $admin = $this->Session->read('AdminLogin'); echo $admin['Admin']['Fullname'];} ?>" />
							<span class="input-group-btn"><button type="submit"
									class="btn btn-warning">Add Comment</button></span>
						</div>
					</div>
				</div>
			</div>
			<!-- <div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="submit" class="btn btn-warning">Add Comment</button>
				</div>
			</div> -->
		</form>
	</div>
	<!-- end ADD COMMENT -->

	<!-- start comment hungdv7 -->
	<div class="article" id="commentListID">
		<h2>
			<span><?php echo count($comments); ?></span> Responses
		</h2>
		<div class="clr"></div>

          
          <?php foreach($comments as $comment):?>
          	<div class="comment" style="position: relative;">
			<!-- <a href="#"> -->
			<img src="/images/cmtIcon.jpg" width="40" height="40" alt=""
				class="userpic" />
			<!-- </a> -->
			<p>
				<?php echo $comment['fullname']?> Says:<br /> <small>				<?php
											
											echo $this->Time->format ( 'F jS, Y h:i A', $comment ['created'], null, new DateTimeZone ( 'Asia/Saigon' ) );
											?>
											</small>
			</p>
			<p class="thebignoob">
				<em> <?php echo $comment['content']?> </em>
			</p>
			<?php if($isAuthor):?>
				<button type="button" data-id="<?php echo $comment['id']; ?>"
				class="btn btn-c btnDel" data-toggle="modal"
				data-target=".bs-example-modal-sm">
				<span class="glyphicon glyphicon-remove"></span>
			</button>			
			<?php endif;?>			
		</div>
          <?php endforeach;?>
     </div>

	<!-- end comment hungdv7 -->

</div>
<!-- Sidebar -->
<div class="sidebar">
      <?php
						echo $this->element ( 'sidebar' );
						?>
				</div>
<!-- end Sidebar -->

<div class="clr"></div>

<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
	aria-labelledby="myLargeModalLabel" aria-hidden="true">
	<div class="modal-dialog modal-sm">
		<div class="modal-content">

			<div class="modal-header bg-custom">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">Confirm Delete</h4>
			</div>
			<form method="post" action="/comments/delete" id="deleteModal">
				<div class="modal-body">
					Do you realy want to delete this Comment? <input type="hidden"
						id="delID" name="comment_id" value="" /> <input type="hidden"
						name="post_id" value="<?php echo $detail['Post']['id']; ?>" />

				</div>
			</form>
			<div class="modal-footer">
				<div class="btn-group btn-group-justified">
					<div class="btn-group">
						<button type="button" class="btn btn-warning"
							onclick="removeComment()">Delete</button>
					</div>
					<div class="btn-group">
						<button type="button" class="btn btn-custom" data-dismiss="modal">Close</button>
					</div>
				</div>

			</div>
		</div>
	</div>
</div>

<div class="modal fade del-post-modal" tabindex="-1" role="dialog"
	aria-labelledby="myLargeModalLabel" aria-hidden="true">
	<div class="modal-dialog modal-sm">
		<div class="modal-content">

			<div class="modal-header bg-custom">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">Confirm Delete</h4>
			</div>
			<form method="post"
				action="/adminPosts/delete/<?php echo $detail['Post']['id']; ?>"
				id="deletePostForm">
				<div class="modal-body">Do you realy want to delete this Post?</div>
			</form>
			<div class="modal-footer">
				<div class="btn-group btn-group-justified">
					<div class="btn-group">
						<button type="button" class="btn btn-warning"
							onclick="removePost()">Delete</button>
					</div>
					<div class="btn-group">
						<button type="button" class="btn btn-custom" data-dismiss="modal">Close</button>
					</div>
				</div>

			</div>
		</div>
	</div>
</div>

